package hutool.crypto;

import cn.hutool.crypto.SecureUtil;
import cn.hutool.crypto.symmetric.SymmetricAlgorithm;
import cn.hutool.crypto.symmetric.SymmetricCrypto;

import java.util.Arrays;

public class SymmetricCryptoTest {
    public static void main(String[] args) {
        aes();
        desc();
    }

    private static void aes() {
        String content = "test中文";
        // 随机生成密钥
        byte[] key = SecureUtil.generateKey(SymmetricAlgorithm.AES.getValue()).getEncoded();
        // 构建
        SymmetricCrypto aes = new SymmetricCrypto(SymmetricAlgorithm.AES, key);

        byte[] encrypt = aes.encrypt(content);
        byte[] decrypt = aes.decrypt(encrypt);
        System.out.println(Arrays.toString(encrypt));
        System.out.println(Arrays.toString(decrypt));

        System.out.println(aes.encryptBase64(content));
        System.out.println(aes.encryptHex(content));
        System.out.println(aes.decryptStr(encrypt));
    }

    private static void desc() {
        String content = "test中文";
        // 随机生成密钥
        byte[] key = SecureUtil.generateKey(SymmetricAlgorithm.DES.getValue()).getEncoded();
        // 构建
        SymmetricCrypto aes = new SymmetricCrypto(SymmetricAlgorithm.DES, key);

        byte[] encrypt = aes.encrypt(content);
        byte[] decrypt = aes.decrypt(encrypt);
        System.out.println(Arrays.toString(encrypt));
        System.out.println(Arrays.toString(decrypt));

        System.out.println(aes.encryptBase64(content));
        System.out.println(aes.encryptHex(content));
        System.out.println(aes.decryptStr(encrypt));
    }
}
